//
//  HHTagCollectionCell.m
//  ZHUIKit
//
//  Created by Basic. on 2021/6/29.
//

#import "HHTagCollectionCell.h"

@implementation HHTagCollectionCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        _textLab = [[UILabel alloc] initWithFrame:self.bounds];
        _textLab.textAlignment = NSTextAlignmentCenter;
        _imgView = [[UIImageView alloc] init];
        
        [self.contentView addSubview:_textLab];
        [self.contentView addSubview:_imgView];
    }
    
    return self;
}
///MARK: - Setter
- (void)setConfig:(HHTagListConfig * _Nonnull)config {
    _config = config;
    self.contentView.backgroundColor = config.itemBgColor;
    if (config.itemCornerRadius>0) {
        self.contentView.layer.cornerRadius = config.itemCornerRadius;
        self.contentView.layer.masksToBounds = YES;
    }
    if (config.itemBorderWidth>0 && config.itemBorderColor) {
        self.contentView.layer.borderColor = config.itemBorderColor.CGColor;
        self.contentView.layer.borderWidth = config.itemBorderWidth;
    }
    self.textLab.font = config.itemFont;
    self.textLab.textColor = config.itemTextColor;
    
    if (config.textNumberOfLines > 0) {
        self.textLab.numberOfLines = config.textNumberOfLines;
    }
    if (config.itemImg) {
        self.imgView.image = config.itemImg;
    }
}
- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];
    
    if (selected) {
        //选中状态
        if (self.config.itemSelectTextColor) {
            self.textLab.textColor = self.config.itemSelectTextColor;
        }
        if (self.config.itemSelectBgColor) {
            self.contentView.backgroundColor = self.config.itemSelectBgColor;
        }
        if (self.config.itemSelectImg) {
            self.imgView.image = self.config.itemSelectImg;
        }
        
    }else{
        self.contentView.backgroundColor = self.config.itemBgColor;
        self.textLab.textColor = self.config.itemTextColor;
        if (self.config.itemImg) {
            self.imgView.image = self.config.itemImg;
        }
    }
}

///MARK: - layoutSubviews
- (void)layoutSubviews
{
    [super layoutSubviews];
    if (self.config.itemImg) {
        if (!self.config.isItemImgRight) {
            
        }else {
            
        }
        
    }else{
        self.textLab.frame = self.bounds;
    }
   
}

- (void)prepareForReuse
{
    [super prepareForReuse];
    
    self.textLab.text = @"";
}

@end
